<?php
	session_start();
   // untuk memanggil file koneksi
   include ("../../../asset/config/koneksi.php");
   // mendefinisikan nilai limit
   $lim = 10;

   // mendefinisikan halaman pertama, jika tidak ada klik halaman maka diisi 0
   $hal	= $_GET['hal'] ? $_GET['hal'] : 0;

   // query untuk mendapatkan jumlah seluruh row
   $sql = "SELECT nama_pasien, nama_ruang, alamat FROM ruang r inner join jenis_ruang j on r.id_jenis = j.id_jenis where id_rs = $_SESSION[idrs] and status = 'Y'"; 
   $res = mysql_query($sql) or die (mysql_error()); 
   $jml = mysql_num_rows($res);

   // menghitung maksimal halaman
   $max = ceil($jml/$lim);

   // melakukan query limit
   $sqlLimit = "SELECT nama_pasien, nama_ruang, alamat FROM ruang r inner join jenis_ruang j on r.id_jenis = j.id_jenis where id_rs = $_SESSION[idrs] and status = 'Y' LIMIT $hal, $lim"; 
   $resLimit = mysql_query($sqlLimit) or die (mysql_error());
?>
<table class="tabel" width="100%">
	<tr align='center'>
		<th width="50">No</th>
		<th>Nama Pasien</th>
		<th>Alamat</th>
		<th>Ruang</th>
		<th width="75">Aksi</th>
	</tr>   
<?php
	// nomor urut ditambah dengan halaman
  $i = 1+$hal;
	while ($data = mysql_fetch_array($resLimit)) {
		if($i%2==0) $bg = '#e9eef3'; else $bg = '#FFFFFF';
		echo 
			"<tr bgcolor = '".$bg."'>
				<td align='center' class='kolom valign'>".$i."</td>
				<td align='center' class='kolom valign'>".$data['nama_pasien']."</td>
				<td class='kolom valign'>".$data['alamat']."</td>
				<td align='center' class='kolom valign'>".$data['nama_ruang']."</td>
				<td align='center' class='kolom valign'>
					<a href='javascript:void(0)' onClick=\"edit_form('$data[id_ruang]')\"> <img src='images/edit.png'> </a>
					<a href='javascript:void(0)' onClick=\"delete_data('$data[id_ruang]','$data[nama_ruang]')\"> <img src='images/delete.png'> </a>
				</td>
			</tr>";
		$i++;
	}
?>
</table>
<table width="99%" style="margin: 0px 5px 0px 5px">
	<tr>
		<td>Jumlah Data : <?=$jml;?></td>
		<td align="right">
			Halaman :
			<?php
				for ($h = 1; $h <= $max; $h++) {
					$list[$h] = $lim * $h - $lim;
					echo " <a href='javascript:void(0)' ";?> onClick="$.get('module/mod_ruang/data.php?hal=<?=$list[$h]?>', null, function(data) {$('#data').html(data);})" <? echo">".$h."</a> ";
				}
			?>
		</td>
	</tr>
</table>
